package com.yand.thinkingInJava.thinkingInJava21.ShareResource;


/**
 * 如果锁住的是另外的一个对象， 其他线程任然可以访问
 *
 */
class DualSynch{

    private Object syncObjet = new Object();

    public synchronized void f(){
        for(int i = 0 ; i < 5; i ++){
            System.out.println("f()");
            Thread.yield();
        }
    }

    public  void g(){
        synchronized (syncObjet){
            for(int i = 0 ; i < 5; i ++){
                System.out.println("g()");
                Thread.yield();
            }
        }
    }


}



public class SyncObject {

    public static void main(String [] args){
         final DualSynch ds = new DualSynch();
         new Thread(){
             public void run(){
                 ds.f();
             }

         }.start();

         ds.g();
    }
}
